define(function() {
	return function($compile, $scope) {
		require(
				[ "AppPathDir/product/reserveInfos/addVisitor",
					"PDUtilDir/dataService",
						"PDUtilDir/inputSelect", "Date", "DateCN",
						"css!DateCss",
						"css!AppPathDir/product/reserveInfos/views/css/css" ],
				function(AddVisitorSupport, DataService, inputSelect) {
					$scope.entity = {
						visitor : []
					};
					$scope.cache = $.extend({
						grid : undefined,
						visitor: new Array()
					}, DataService.getObject('product.search.reserve'));
//					$scope.cache = $.extend({
//						costs_str: $sce.trustAsHtml($scope.cache.costs),
//						notes_str: $sce.trustAsHtml($scope.cache.notes)
//					});
					$.ajax({
						url : getServer() + "/flea/hclv/getCertificates.htmls",
						success : function(data) {
                            if (data.status != 200) {
                                return;
                            }
							$scope.cache.certificates = data.data;
							var certificates = data.data, len = certificates.length, obj = new Map();
							for(var i = 0; i < len; i++){
								obj.set(certificates[i].dictCode, certificates[i].dictName);
							}
							$scope.cache.certificatesObject = obj;
							$scope.$digest();
						}
					});
					
					$scope.addVisitorSupport = AddVisitorSupport($scope, $compile);

					$scope.reloadSupport = {
						run : function() {
							var selecteds = $scope.cache.visitor,
								len = selecteds.length;
								i = 0,
								datas = DataService.getObject('product.search.reserve.visitors');
							$.each(datas, function(index, row) {
								len = selecteds.length;
								for(i = 0; i < len; i++){
									if (row.id == selecteds[i].id)
										break;
								}
								if(i == len)
									selecteds.push(row);
							});
							$scope.$digest();
						}
					};
					
					$scope.removeVisitor = function(id) {
						var data = $scope.cache.visitor, len = data.length;

						for (var i = 0; i < len; i++) {
							if (id == data[i].id) {
								data.splice(i, 1);
								break;
							}
						}
					};
					$scope.payFun = function() {
						$.ajax({
							url : getServer()
									+ "/flea/hclv/visitor/order/loadOrder.htmls",
							method : 'post',
							data : {
								model : JSON.stringify({
									addVisitors : $scope.cache.visitor,
									timeTableId : $scope.cache.timeTable.id
								})
							},
							success : function(data) {
								if (data.status != 200) {
									return;
								}
								$scope.cache.visitor = data.data;
								window.top.tabs.closeTab($scope.cache.id + '_reserve');
								window.parent.location.href = getServer() + '/flea/home.htmls#/order';
							}
						});
					};
					$scope.$digest();
				})
	}
});